//
//  UILabel+Extral.m
//  Notepad
//
//  Created by ylh on 14-3-4.
//  Copyright (c) 2014年 ylh. All rights reserved.
//

#import "UILabel+zframework.h"

@implementation UILabel (zframework)


-(id)initWithFrame:(CGRect)frame text:(NSString *)text textColor:(UIColor *)textColor textFont:(UIFont *)textFont aliment:(NSTextAlignment)aliment;
{
    if (self = [self initWithFrame:frame]) {
        [self setText:text];
        self.font = textFont;
        self.textColor = textColor;
        self.backgroundColor = [UIColor clearColor];
        self.textAlignment = aliment;
        return self;
    }
    
    return nil;
}

- (void) setVerticalAlignmentTop
{
    CGSize textSize = [self.text sizeWithFont:self.font
                            constrainedToSize:self.frame.size
                                lineBreakMode:self.lineBreakMode];
    
    CGRect textRect = CGRectMake(self.frame.origin.x,
                                 self.frame.origin.y,
                                 self.frame.size.width,
                                 textSize.height);
    [self setFrame:textRect];
    [self setNeedsDisplay];
}

-(void)autoHeight{
    [self setNumberOfLines:0];
    self.lineBreakMode = UILineBreakModeWordWrap;
    //自动高度
    CGSize maxSize = CGSizeMake(self.width, 1000);
    self.size = [self.text sizeWithFont:self.font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
}

@end
